home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group01b.txt
/
000142_icon-group-sender_Thu Sep 13 12:32:09 2001.msg
< prev
next >
Wrap
Internet Message Format
|
2002-01-03
|
3KB
Return-Path: <icon-group-sender>
Received: (from root@localhost)
by baskerville.CS.Arizona.EDU (8.11.1/8.11.1) id f8DJUsE26090
for icon-group-addresses; Thu, 13 Sep 2001 12:30:54 -0700 (MST)
Message-Id: <200109131930.f8DJUsE26090@baskerville.CS.Arizona.EDU>
From: Steve Wampler <swampler@noao.edu>
X-Newsgroups: comp.lang.icon
Subject: Re: join
Date: Thu, 13 Sep 2001 08:41:15 -0700
X-Complaints-To: abuse@noao.edu
X-Accept-Language: en
To: icon-group@cs.arizona.edu
Errors-To: icon-group-errors@cs.arizona.edu
Status: RO
Content-Length: 2114
Andrew Hamm wrote:
>
> Steve Wampler wrote in message <3B97AB3B.12DBFBEE@noao.edu>...
> >
> >A question for people: How equivalent are the following approaches?
> >
> > f := open(filename)
> > while line := read(f) do ...
> > close(f)
> >
> >and
> >
> > cf := create (!(f := open(filename)) | (close(f),&fail))
> > while line := @cf do ...
> >
>
> OK - I'll bite. Is this going to be another trick question like comparing
>
> while expr
>
> with some sort of generator in the implementation book? can't remember the
> alternatives, and my book is at home.
Well, it wasn't planned that way, but probably someone with more detailed
knowledge of the implementation can find a number of differences at that
level!
> Anyways, ignoring the lack of error checking, all I can see is that cf is
> restartable to repoen the file. Depending on the scope of f, it could be
> private to the coexpression and therefore inaccessible.
>
> What am I missing?
I don't think you're missing anything. Here are the things I see as
"different" (others will no doubt disagree!):
(1) scope of f affects behavior. Just as Andrew says, if f is local when
the coexpression is created, then it's inaccessible outside the
coexpression. Why is this a difference? Because it means...
(2) if you break out of the loop early in the first example, you can still
close the file. if you break out of the loop early in the second (and
f is inaccessible), the only way to close the file is to exhaust the
co-expression, via (say)
while @cf
which could be a significant performance hit, but...
(3) the coexpression version provides automatic closing of the file when you're
done reading it. In the first approach, if you forget the close(f) after
the while, the file remains open.
(4) What happens if you refresh the co-expression before it "finishes"? (Ok,
this probably isn't a real difference, but is more likely to sneak up on you
than doing the equivalent in the first case...)
--
Steve Wampler- SOLIS Project, National Solar Observatory
swampler@noao.edu